package com.maochang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maochang.mapper.PsInspectiontaskDetailMapper;
import com.maochang.mapper.PsSolvetaskDetailMapper;
import com.maochang.pojo.PsInspectiontaskDetail;
import com.maochang.pojo.PsSolvetaskDetail;
import com.maochang.service.PsSolvetaskDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("PsSolvetaskDetailServiceImpl")
public class PsSolvetaskDetailServiceImpl extends ServiceImpl<PsSolvetaskDetailMapper, PsSolvetaskDetail> implements PsSolvetaskDetailService {

    @Resource //消缺子表操作
    private  PsSolvetaskDetailMapper  psSolvetaskDetailMapper;
    @Resource //巡检子表操作
    private PsInspectiontaskDetailMapper psInspectiontaskDetailMapper;
    /**
     * 增加 消缺子信息表
     * @param PsSolvetaskDetail
     * @return
     */
    @Override
    public boolean addXiaoQuZiBiao(PsSolvetaskDetail PsSolvetaskDetail) {
        int  row=   psSolvetaskDetailMapper.insert(PsSolvetaskDetail);
        return row>0?true:false;
    }

    @Override
    public  Page<PsInspectiontaskDetail> chaXueXin(Integer taskId,int current,int size) {
        QueryWrapper<PsSolvetaskDetail> wrapper1= Wrappers.query();
        wrapper1.eq("taskId",taskId);
        List<PsSolvetaskDetail> psSolvetaskDetails = psSolvetaskDetailMapper.selectList(wrapper1);
        List<Integer> ShuZi=new ArrayList<>();
        for(PsSolvetaskDetail aa:psSolvetaskDetails){
            ShuZi.add(aa.getInspectionTaskDelId());
        }
        QueryWrapper<PsInspectiontaskDetail> wrapper2= Wrappers.query();
        if(ShuZi.size()>0){
            wrapper2.in("id",ShuZi);
        }else {
            wrapper2.in("id",0);
        }
        Page<PsInspectiontaskDetail> psliPage=new Page<>(current,size);
        Page<PsInspectiontaskDetail> ac = psInspectiontaskDetailMapper.selectPage(psliPage,wrapper2);
        return  ac;
    }
}
